$(document).ready(function(){
    $("#book_brand_content li[id^='pub_txt_']").mouseover(function(){
        var obj = $(this);
        var id = obj.attr("id").replace(/pub_txt_/,'');
        var pic_obj = $("#pub_img_"+id);
        var pic_text_obj = $("#text_pub_"+id);
        if(pic_text_obj.attr("id")!=undefined || $.trim(pic_obj.html())!=''){
            obj.siblings("li[id^='pub_img_']").each(function(){
                var img_obj = $(this);
                var img_id = img_obj.attr("id").replace(/pub_img_/,'');
                var txt_obj = $("#pub_txt_"+img_id);
                if(img_obj.attr("class").indexOf("hidden")==-1){
                    img_obj.addClass("hidden");
                    txt_obj.removeClass("hidden");
                    return false;
                }
            });
            obj.addClass("hidden");
            if($.trim(pic_obj.html())=="")
                pic_obj.html($.trim(pic_text_obj.text()));
            pic_obj.removeClass("hidden");
        }
    });
    $('#strategic_partner_content').ddcycle({
        fx: 'scrollUp',
        speed:	 1000,
        timeout:6000,
        pause:	 true
    });
    $('#slidecontent').ddcycle({
        fx: 'scrollHorz',
        speed:	 500,
        timeout:	3000,
        pause:	 true,
        pager:	 '#slidelabel_nav',
        pagerCss:    'active',
        pagerEvent:	'mouseover'
    });
    $('#book_hotsale_slide').ddcycle({
        fx:'scrollHorz',
        timeout:0,
        speed:500,
        after:book_hotsale_after,
        next:'#btn_next',
        prev:'#btn_prev'
    });
    $('#book_infor a').mouseover(function(){
        var obj = $(this);
        var id = obj.attr("id").replace(/book_infor_/,'');
        var old_id;
        if(obj.attr("class")!="active"){
            obj.parent().siblings("li").each(function(){
                var sb_obj = $(this).children('a');
                if(sb_obj.attr("class")=="active"){
                    old_id = sb_obj.attr("id").replace(/book_infor_/,'');
                    sb_obj.removeAttr("class");
                }
            });
            obj.attr("class","active");
            var big_obj = $('#book_infor_detail_'+id);
            var big_txt_obj = $('#book_infor_detail_txt_'+id);
            var old_big_obj = $('#book_infor_detail_'+old_id);
            old_big_obj.hide();
            if(big_txt_obj.text() != ''){
                big_obj.html(big_txt_obj.text());
            }else{
                big_obj.html(big_obj.html());
            }
            big_obj.show();
        }
    });
    $("#book_tab1_top a[id^='tab1_host_tab_']").mouseover(function(){
        var obj = $(this);
        if(obj.attr("class").indexOf('active')==-1){
            var id = obj.attr("id").replace(/tab1_host_tab_/,'');
            var tab_obj = $("#tab1_"+id);
            var active_obj = obj.siblings('.active');
            var active_id = active_obj.attr("id").replace(/tab1_host_tab_/,'');
            var active_tab_obj = $("#tab1_"+active_id);
            active_obj.removeClass("active");
            obj.addClass("active");
            if($.trim(tab_obj.html())==''){
                var text_obj = $("#text_tab1_"+id);
                tab_obj.html($.trim(text_obj.text().replace(/textarea_tab1/g,'textarea')));
            }
            active_tab_obj.addClass("hidden");
            tab_obj.removeClass("hidden");
        }
    });
    $("#book_djtg_content").delegate("a[id^='djtg_tab_']","mouseover",function(){
        var obj = $(this);
        if(obj.attr("class").indexOf('active')==-1){
            var id = obj.attr("id").replace(/djtg_tab_/,'');
            var tab_obj = $("#djtg_area_"+id);
            var active_obj = obj.siblings('.active');
            var active_id = active_obj.attr("id").replace(/djtg_tab_/,'');
            var active_tab_obj = $("#djtg_area_"+active_id);
            active_obj.removeClass("active");
            obj.addClass("active");
            var text_obj = $("#djtg_text_"+id);
            var text = $.trim(text_obj.text());
            if(text!=''){
                tab_obj.html(text);
            }
            active_tab_obj.addClass("hidden");
            tab_obj.removeClass("hidden");
        }
    });
    $("#book_tsjc_tab a[id^='tsjc_tab_']").live("mouseover",function(){
        var obj = $(this);
        if(obj.attr("class").indexOf('active')==-1){
            var id=obj.attr("id").replace(/tsjc_tab_/,'');
            var tab_obj = $("#tsjc_area_"+id);
            var active_obj = obj.siblings('.active');
            var active_id = active_obj.attr("id").replace(/tsjc_tab_/,'');
            var active_tab_obj = $("#tsjc_area_"+active_id);
            active_obj.removeClass("active");
            obj.addClass("active");
            var text_obj = $("#tsjc_text_"+id);
            var text = $.trim(text_obj.text());
            if(text!=''){
                tab_obj.html(text);
            }
            active_tab_obj.addClass("hidden");
            tab_obj.removeClass("hidden");
        }
    });
    $("#book_tjss_tab a[id^='tjss_tab_']").live("mouseover",function(){
        var obj = $(this);
        if(obj.attr("class").indexOf('active')==-1){
            var id=obj.attr("id").replace(/tjss_tab_/,'');
            var tab_obj = $("#tjss_area_"+id);
            var active_obj = obj.siblings('.active');
            var active_id = active_obj.attr("id").replace(/tjss_tab_/,'');
            var active_tab_obj = $("#tjss_area_"+active_id);
            active_obj.removeClass("active");
            obj.addClass("active");
            var text_obj = $("#tjss_text_"+id);
            var text = $.trim(text_obj.text());
            if(text!=''){
                tab_obj.html(text);
            }
            active_tab_obj.addClass("hidden");
            tab_obj.removeClass("hidden");
        }
    });
    $("#discount_bestsell_bang li[id^='bestsell_bang_area_txt_']").live("mouseover",function(){
        var obj = $(this);
        var id= obj.attr("id").replace(/bestsell_bang_area_txt_/,'');
        var pic_obj = $("#bestsell_bang_area_pic_"+id);
        var pic_text_obj = $("#bestsell_bang_area_text_"+id);
        obj.siblings("li.detail").each(function(){
            var img_obj = $(this);
            var img_obj_id = img_obj.attr("id").replace(/bestsell_bang_area_pic_/,'');
            var txt_obj =$("#bestsell_bang_area_txt_"+img_obj_id);
            var text_obj = $("#bestsell_bang_area_text_"+img_obj_id);
            if(img_obj.attr("class").indexOf('hidden')==-1){
                img_obj.addClass("hidden");
                if($.trim(txt_obj.html())=="")
                    txt_obj.html($.trim(text_obj.text()));
                txt_obj.removeClass("hidden");
                return false;
            }
        });
        obj.addClass("hidden");
        if($.trim(pic_obj.html())=="")
            pic_obj.html($.trim(pic_text_obj.text()));
        pic_obj.removeClass("hidden");
    });

    $("#book_tab2_slide").ddcycle({
        fx:"fade",
        speed:0,
        timeout:8000,
        pause:1,
        pauseOnPagerHover:1,
        pager: '#book_tab2_top',
        pagerEvent:'mouseover',
        pagerCss:'active',
        pagerAnchorBuilder:tab2MakePageAnchor,
        before:tab2OnBefore
    });

    $("#book_tab3_slide").ddcycle({
        fx:"fade",
        speed:0,
        timeout:8000,
        pause:1,
        pauseOnPagerHover:1,
        pager: '#book_tab3_top',
        pagerEvent:'mouseover',
        pagerCss:'active',
        pagerAnchorBuilder:tab3MakePageAnchor,
        before:tab3OnBefore
    });

    $("#book_bestsell_bang_tab1 a[id^='bbb_tab_']").mouseover(function(){
        var obj = $(this);
        if(obj.attr("class").indexOf('active')==-1){
            var id = obj.attr("id").split("_");
            var key = id[0]+'_'+id[1]+'_'+id[2]+'_';
            id = id[3];
            var timeobj = $("#bbb_time_tab a.active");
            var timeid = timeobj.attr("id").replace(/bbb_/,'');
            var tab_obj = $("#bbb_ul_"+id+"_"+timeid);
            var active_obj = obj.siblings('.active[id^="'+key+'"]');
            var active_id = active_obj.attr("id").split('_');
            active_id = active_id[3];
            var active_tab_obj = $("#bbb_ul_"+active_id+"_"+timeid);
            active_obj.removeClass("active");
            obj.addClass("active");
            if($.trim(tab_obj.html())==""){
                var text_obj = $("#text_"+id+"_"+timeid);
                tab_obj.html($.trim(text_obj.text().replace(/textarea_tab2/g, 'textarea')));
            }
            active_tab_obj.addClass("hidden");
            tab_obj.removeAttr('class');
        }
    });
    $("#bbb_time_tab a[id^='bbb_']").mouseover(function(){
        var obj = $(this)
        if(obj.attr("class").indexOf('active')==-1){
            var id = obj.attr("id").replace(/bbb_/,'');
            var tab_arr = {
                '24hours':null,
                'week':null,
                'month':null
            };
            $("#book_bestsell_bang_tab1 a").each(function(){
                var $this = $(this);
                var $this_id = $this.attr("id").replace(/bbb_tab_/, '');
                var $index = $this_id.slice(-1);
                $this_id =$this_id.substring(0, $this_id.indexOf('_', 0));
                if($this.attr("class").indexOf('active')!=-1)
                    tab_arr[$this_id] = $index;
                if(id==$this_id){
                    $this.removeClass("hidden");
                }else{
                    $this.addClass("hidden");
                }
            });
            $("#book_bestsell_bang div[id^='bbb_ul_']").each(function(){
                var $this = $(this) ;
                var $this_id = $this.attr("id").replace(/bbb_ul_/,'');
                var $index = $this_id.substr(0,1);
                $this_id = $this_id.substr(2, $this_id.length-2);
                if(id==$this_id){
                    if(tab_arr[$this_id]==$index){
                        $this.removeAttr("class");
                        if($.trim($this.html())==""){
                            var text_obj = $("#text_"+$index+"_"+$this_id);
                            $this.html($.trim(text_obj.text().replace(/textarea_tab2/g,'textarea')));
                            text_obj.remove();
                        }
                    }
                }else{
                    if(tab_arr[$this_id]==$index){
                        $this.addClass("hidden");
                    }
                }
            });
            var active_obj = obj.siblings('.active');
            active_obj.removeClass("active");
            obj.addClass("active");
        }
    });
    $("#book_bestsell_bang").delegate("li[id^='bbb_li_txt_']","mouseover",function(){
        var obj = $(this);
        var id = obj.attr("id").replace(/bbb_li_txt_/,'');
        var pic_obj = $("#bbb_li_img_"+id);
        var pic_text_obj = $("#bbb_text_"+id);
        obj.siblings("li.detail").each(function(){
            var img_obj = $(this);
            var img_obj_id = img_obj.attr("id").replace(/bbb_li_img_/,'');
            var txt_obj =$("#bbb_li_txt_"+img_obj_id);
            if(img_obj.attr("class").indexOf('hidden')==-1){
                img_obj.addClass("hidden");
                txt_obj.removeClass("hidden");
                return false;
            }
        });
        obj.addClass("hidden");
        if($.trim(pic_obj.html())=="")
            pic_obj.html($.trim(pic_text_obj.text()));
        pic_obj.removeClass("hidden");
    });
    $("#book_tab4_top a[id^='tab4_host_tab_']").mouseover(function(){
        var obj = $(this);
        if(obj.attr("class").indexOf('active')==-1){
            var id = obj.attr("id").replace(/tab4_host_tab_/,'');
            var tab_obj = $("#tab4_"+id);
            var active_obj = obj.siblings('.active');
            var active_id = active_obj.attr("id").replace(/tab4_host_tab_/,'');
            var active_tab_obj = $("#tab4_"+active_id);
            active_obj.removeClass("active");
            obj.addClass("active");
            if($.trim(tab_obj.html())==''){
                var text_obj = $("#text_tab4_"+id);
                tab_obj.html($.trim(text_obj.text()));
            }
            active_tab_obj.addClass("hidden");
            tab_obj.removeClass("hidden");
        }
    });
});

function tab2MakePageAnchor(i,e){
    var text = tab2_name[i];
    var html = '<a id="tab2_host_tab_'+i+'" href="javascript:void(0)" title="'+text+'"><span>'+text+'</span></a>';
    return html;
}

function tab2OnBefore(c,n,o){
    var obj = $(n);
    var id = obj.attr("id").replace(/tab2_/,'');
    if($.trim(obj.html())==""){
        var text = $("#text_tab2_"+id);
        obj.html(text.text());
        text.remove();
    }
}

function tab3MakePageAnchor(i,e){
    var text = tab3_name[i];
    var html = '<a id="tab3_host_tab_'+i+'" href="javascript:void(0)" title="'+text+'"><span>'+text+'</span></a>';
    return html;
}

function tab3OnBefore(c,n,o){
    var obj = $(n);
    var id = obj.attr("id").replace(/tab3_/,'');
    if($.trim(obj.html())==""){
        var text = $("#text_tab3_"+id);
        obj.html(text.text());
        text.remove();
    }
}

function book_hotsale_after(c,n,o){
    var index = o.currSlide+1;
    $("#book_hotsale_curr").html(index+"/"+book_hotsale_json_count);
}

function rmzz_active_num(i){
    var obj = $("#rmzz_text_list li span[id='rmzz_num_"+i+"']");   
    obj.addClass("active");
}

function rmzz_num(i){
    var obj = $("#rmzz_text_list li span[id='rmzz_num_"+i+"']");
    if(i>1){
        obj.removeClass("active");
    }
}